from PySide6.QtWidgets import QWidget, QVBoxLayout, QRadioButton, QButtonGroup
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QWidget, QVBoxLayout, QComboBox, QLabel
from logger.manager import LogManager

class ThemePanel(QWidget):
    theme_changed = Signal(str)
    
    def __init__(self, theme_manager):
        super().__init__()
        self.theme_manager = theme_manager
        self.log_manager = LogManager()
        self.app_log = self.log_manager.get_log_file_path('app')
        self.init_ui()
        self.setObjectName("theme_panel")
        
    def init_ui(self):
        layout = QVBoxLayout(self)
        layout.setContentsMargins(16, 16, 16, 16)
        layout.setSpacing(12)
        
        # 主题选择下拉框
        theme_label = QLabel("选择主题：")
        self.theme_combo = QComboBox()
        self.theme_combo.addItems(self.theme_manager.get_available_themes())
        current_theme = self.theme_manager.get_current_theme()
        self.theme_combo.setCurrentText(current_theme)
        self.theme_combo.currentTextChanged.connect(self.on_theme_changed)
        
        layout.addWidget(theme_label)
        layout.addWidget(self.theme_combo)
        layout.addStretch()
        
    def on_theme_changed(self, theme_name):
        try:
            self.theme_manager.set_current_theme(theme_name)
            self.log_manager.write_log(self.app_log, f"切换主题: {theme_name}", "Theme")
            self.theme_changed.emit(theme_name)
        except Exception as e:
            self.log_manager.write_log(self.app_log, f"切换主题失败: {str(e)}", "Theme")